package com.heima.controller;

import com.heima.pojo.PageBean;
import com.heima.pojo.Partner;
import com.heima.pojo.dto.PartnerQueryParamDto;
import com.heima.service.PartnerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/api/user-service/partner")
public class PartnerController {
    @Autowired
    private PartnerService partnerService;
    @PostMapping
    @ApiOperation("添加合作商")
    public Boolean addPartner(@RequestBody Partner partner){
        log.info("要添加的商品的信息是：{}",partner);
        return partnerService.addPartner(partner);
    }
    @GetMapping("/search")
    @ApiOperation("分页查询合作商")
    public PageBean selectPartner( PartnerQueryParamDto partnerDto){
        log.info("要查询的partner 名字是 {}",partnerDto.getName());
        return partnerService.selectPartner(partnerDto);
    }
    @GetMapping("/{id}")
    @ApiOperation("根据ID查询回显")
    public Partner selectPartnerById(@PathVariable int id){
        log.info("要查询回显的id为：{}",id);
        return partnerService.selectPartnerById(id);
    }
    @PutMapping("/{id}")
    @ApiOperation("删除合作商")
    public Boolean updatePartner(@PathVariable int id,@RequestBody Partner partner){
        log.info("要修改的id是：{} ,内容是：{}",id , partner) ;
        return partnerService.updatePartner(id, partner);
    }
    @DeleteMapping("/{id}")
    @ApiOperation("删除合作商(不完全)")
    public  Boolean DeletePartner (@PathVariable int id){
        log.info("要删除的合作商为：{}",id);
        return partnerService.deletePartner(id);
    }
}
